package org.csu.mypetstoreback.service;

import org.csu.mypetstoreback.domain.Account;
import org.csu.mypetstoreback.domain.Product;
import org.csu.mypetstoreback.persistence.AccountMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AccountService {
    @Autowired
    private AccountMapper accountMapper;

    public List<Account> getAccounts(){
        return accountMapper.getAccounts();
    }

    public void updateAccount(Account account){
        accountMapper.updateAccount(account);
//        accountMapper.updateProfile(account);
//        accountMapper.updateSignon(account);
    }

    public void deleteAccount(Account account){
        accountMapper.deleteAccount(account);
        accountMapper.deleteProfile(account);
        accountMapper.deleteSignon(account);
    }

    public Account getAccount(String username){
        return accountMapper.getAccountByUsername(username);
    }

    public List<Account> searchAccountList(String keyword) {
        return accountMapper.searchAccountList("%" + keyword.toLowerCase() + "%");
    }

}
